//
//  AddDetailViewController.m
//  AddressBookCoreData
//
//  Created by dllo on 15/11/20.
//  Copyright © 2015年 Dior_3g. All rights reserved.
//

#import "JHCAddDetailViewController.h"
#import "AddressBook.h"
#import "JHCLTView.h"
#import "JHCCoreData.h"

#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height

@interface JHCAddDetailViewController ()

@property(nonatomic, strong) JHCCoreData *manager;

@end

@implementation JHCAddDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
    
    JHCLTView *nameView = [[JHCLTView alloc] initWithFrame:CGRectMake(WIDTH / 100 * 10, HEIGHT / 100 * 20, WIDTH / 100 * 80, HEIGHT / 100 * 7)];
    [self.view addSubview:nameView];
    nameView.label.text = @"姓名";
    
    
    JHCLTView *sexView = [[JHCLTView alloc] initWithFrame:CGRectMake(WIDTH / 100 * 10, HEIGHT / 100 * 30, WIDTH / 100 * 80, HEIGHT / 100 * 7)];
    [self.view addSubview:sexView];
    sexView.label.text = @"性别";
    
    
    JHCLTView *numberView = [[JHCLTView alloc] initWithFrame:CGRectMake(WIDTH / 100 * 10, HEIGHT / 100 * 40, WIDTH / 100 * 80, HEIGHT / 100 * 7)];
    [self.view addSubview:numberView];
    numberView.label.text = @"学号";
    
    
    JHCLTView *phoneView = [[JHCLTView alloc] initWithFrame:CGRectMake(WIDTH / 100 * 10, HEIGHT / 100 * 50, WIDTH / 100 * 80, HEIGHT / 100 * 7)];
    [self.view addSubview:phoneView];
    phoneView.label.text = @"电话";
    
    
    
    JHCLTView *qqView = [[JHCLTView alloc] initWithFrame:CGRectMake(WIDTH / 100 * 10, HEIGHT / 100 * 60, WIDTH / 100 * 80, HEIGHT / 100 * 7)];
    [self.view addSubview:qqView];
    qqView.label.text = @"QQ";
    
    
    
    JHCLTView *nativeView = [[JHCLTView alloc] initWithFrame:CGRectMake(WIDTH / 100 * 10, HEIGHT / 100 * 70, WIDTH / 100 * 80, HEIGHT / 100 * 7)];
    [self.view addSubview:nativeView];
    nativeView.label.text = @"籍贯";
    
    
    self.manager = [JHCCoreData shareCoreData];
    
    NSLog(@"manager = %@", [self.manager applicationDocumentsDirectory]);
    
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"AddressBook" inManagedObjectContext:self.manager.managedObjectContext];
    
    AddressBook *addressModel = [[AddressBook alloc] initWithEntity:entity insertIntoManagedObjectContext:self.manager.managedObjectContext];
    
    addressModel.name = nameView.textField.text;
    addressModel.sex = nameView.textField.text;
    addressModel.number = (NSNumber *)nameView.textField.text;
    addressModel.phone = (NSNumber *)nameView.textField.text;
    addressModel.qq = (NSNumber *)nameView.textField.text;
    addressModel.native = nameView.textField.text;
    
    [self.manager saveContext];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
